import merged from 'obj-merged';
import { SELECT_TAB, RECEIVE_SLIDER, SLIDER_FAILED, RECEIVE_HOT, RECEIVE_GROUP, RECEIVE_GROUPITEM, REQUEST_NEWS, RECEIVE_NEWS, RECORD_SCROLLT } from '../Constants/ActionTypes';

const homePage = (state = { selectedTab: "home", isFetching: false, sliderisFetching: false, sliderload: [], hotload: [], groupload: [], groupitemload: [], newsload: [], pageNo: 0, limit: 5, scrollT: 0 }, action) => {

    switch (action.type) {
        case SELECT_TAB:
            return Object.assign({}, state, {
                selectedTab: action.tab
            });
        case RECEIVE_SLIDER:
            return Object.assign({}, state, {
                sliderret: action.ret,
                slidermsg: action.msg,
                slidertotals: action.totals,
                sliderload: action.sliderload,
                sliderisFetching: false
            });
        case SLIDER_FAILED:
            return Object.assign({}, state, {
                payload: action.payload
            });
        case RECEIVE_HOT:
            return Object.assign({}, state, {
                hotload: action.hotload
            });
        case RECEIVE_GROUP:
            return Object.assign({}, state, {
                groupload: action.groupload
            });
        case RECEIVE_GROUPITEM:
            return Object.assign({}, state, {
                classify: action.classify,
                groupitemload: action.groupitemload
            });
        case REQUEST_NEWS:
            return Object.assign({}, state, {
                tab: "home",
                isFetching: true
            });
        case RECEIVE_NEWS:
            return Object.assign({}, state, {
                isFetching: false,
                pageNo: action.pageNo,
                limit: action.limit,
                newstotals: action.newstotals,
                newsload: action.newsload
            });
        case RECORD_SCROLLT:
            return Object.assign({}, state, {
                tab: action.tab,
                scrollT: action.scrollT
            });
        default:
            return state;
    }
}

export default homePage;